package com.lite.api.controller.publics.middletab;


import com.lite.business.convert.middletab.MiddleTabConvert;
import com.lite.business.entity.commodities.ContractCommodity;
import com.lite.business.entity.middletab.MiddleTab;
import com.lite.business.exception.BusinessException;
import com.lite.business.service.middletab.MiddleTabService;
import com.lite.common.dto.ResultResponse;
import com.lite.common.utils.ResultResponseUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author stranger
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/middle-tab")
public class MiddleTabController {
    @Autowired
    MiddleTabService middletabService;

    @Autowired
    MiddleTabConvert middletabConvert;


    /**
     * 新增一个合同订购商品信息
     *
     * @param middleTab 订购商品对象
     * @return 是否新增成功
     * @throws BusinessException 业务异常
     */
    @PostMapping("/addContractCommodity")
    public ResultResponse<Boolean> addContractCommodity(@RequestBody @NotNull MiddleTab middleTab) throws BusinessException {
        return ResultResponseUtils.success(middletabService.addContractCommodity(middleTab), "新增订购商品信息成功");
    }

    /**
     * 删除一个合同订购商品信息
     *
     * @param middleTabId 订购ID
     * @return 是否删除成功
     * @throws BusinessException 业务异常
     */
    @DeleteMapping("/removeContractCommodity")
    public ResultResponse<Boolean> removeContractCommodity(@RequestParam @NotNull Integer middleTabId) throws BusinessException {
        return ResultResponseUtils.success(middletabService.removeContractCommodity(middleTabId), "删除订购商品成功");
    }

    /**
     * 分页获取订购合同商品信息列表
     *
     * @param page       页数
     * @param size       容量
     * @param contractId 合同ID
     * @return 商品信息列表
     * @throws BusinessException 业务异常
     */
    @GetMapping("/listContractCommodity")
    public ResultResponse<List<ContractCommodity>> listContractCommodity(
            @RequestParam @NotNull Integer page,
            @RequestParam @NotNull Integer size,
            @RequestParam @NotNull Integer contractId) throws BusinessException {
        return ResultResponseUtils.success(middletabService.listContractCommodity(page, size, contractId), "获取订购商品列表信息成功");
    }

}
